#include "lstring.h"
#include <iostream>

namespace lstring
{
    void split(std::vector<std::string>& strList,std::string& text,char ch)
    {
        using namespace std;
        int pos = 0;
        int count = 0;
        while(true)
        {
            string::size_type n = text.find(ch,pos);

            if( n == string::npos )
            {
                strList.push_back(text.substr(pos,text.length() - pos));
                break;
            }

            count = n - pos;
            strList.push_back(text.substr(pos,count));
            pos = n + 1;
        }
    }


    void demo()
    {
        using namespace std;

        vector<string> strlist;
        string str = "just,a,test!";
        char ch = ',';

        split(strlist,str,ch);

        for(vector<string>::size_type i = 0; i < strlist.size() ; i ++)
        {
            cout<<strlist[i]<<endl;
        }
    }
};


